import pygame
from pygame.sprite import Sprite


class Bullet(Sprite):
    def __init__(self, aisettings, screen, charter):
        super(Bullet, self).__init__()
        self.screen = screen
        self.image = pygame.image.load('picture/bullet_01.png')
        self.image = pygame.transform.scale(self.image, (15, 15))  # 图片
        self.rect = self.image.get_rect()
        self.rect.centerx = charter.rect.centerx
        self.rect.centery = charter.rect.centery  # 在人物中心创造子弹
        self.movey = float(self.rect.centery)
        self.movex = float(self.rect.centerx)
        self.speed_factor = aisettings.bullet_speed

    def update(self):
        self.movex += self.speed_factor
        self.rect.x = self.movex

    def bilitime(self):
        self.screen.blit(self.image, self.rect)
